package com.a16.yuejian.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.javabean.Master;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 王子恒 on 2017/10/19.
 */

public class CoachAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public CoachAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.coach_cardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Master entity = (Master) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.coach_name.setText(entity.getCoachname());
        viewHolder.coach_intro.setText(entity.getCoachintroduction());
        Picasso.with(mContext).load("http://10.0.2.2:8080/neu_yuejian201/public/photo/"+entity.getCoachpic()).into(viewHolder.coach_img);

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView coach_img;
        TextView coach_name,coach_intro;
        LinearLayout coach_container;

        public ViewHolder(View itemView) {
            super(itemView);
            coach_name = (TextView) itemView.findViewById(R.id.coach_name);
            coach_img = (ImageView) itemView.findViewById(R.id.coach_img);
            coach_intro = (TextView) itemView.findViewById(R.id.coach_intro);
            coach_container= (LinearLayout)itemView.findViewById(R.id.coach_container);
        }
    }
}
